#!/bin/env python

import time
import cv2
import numpy as np

pic_path = "../resource/pic/img_005.jpg"
windowName = "Scharr"

pic1 = cv2.imread(pic_path)
pic1_h, pic1_w, pic1_chn = pic1.shape

# Scharr算子必须分开计算x轴与y轴
# Scharr算子计算x轴梯度, 只有垂直方向的边缘
dx = cv2.Scharr(pic1, -1, dx = 1, dy = 0)
# Scharr算子计算y轴梯度, 只有水平方向的边缘
dy = cv2.Scharr(pic1, -1, dx = 0, dy = 1)
# 合并图像
img = cv2.addWeighted(dx, 0.5, dy, 0.5, 0)

cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
cv2.resizeWindow(windowName, 500 * 4, 500)
cv2.imshow(windowName, np.hstack((pic1, dx, dy, img)))

while True:
    if cv2.waitKey(0) == ord('q'):
        break

print('销毁窗口')
cv2.destroyAllWindows()


